<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<script type="text/javascript">
		
		var sourceTable;
		$(function(){
			var tbl = sourceTable= new S.Table({
				el:'#tbl001',
				pager:true,
				pageSize:30,
				multiselect:false,
				dbclick:function(data){
					editSource(data.id, data.name);
				}
			});
			
			$('#btn_source_add').click(function(){
				S.prompt('增加','名称',function(val){
					if(val == ''){new S.Info({text:'请输入名称',type:'warn'}).show();return;}
					S.request({
						url:'${webcontext}/${pathvar.admin}/blog/source/save',
						data:{name:val},
						success:function(){
							new S.Info({text:'操作成功',type:'success'}).show();
							tbl.reload();
						}
					});
				},'info');
			});
			
			
			function editSource(id,name){
				S.prompt('修改','名称',function(val){
					if(val == ''){new S.Info({text:'请输入名称',type:'warn'}).show();return;}
					S.request({
						url:'${webcontext}/${pathvar.admin}/blog/source/update',
						data:{id:id,name:val},
						success:function(){
							new S.Info({text:'操作成功',type:'success'}).show();
							tbl.reload();
						}
					});
				},'info',null,null,name);
			}
			
			$('#btn_source_edit').click(function(){
				var items = tbl.getCheckedRow();
				if(items.length !=1){new S.Info({text:'请选择来源',type:'warn'}).show();return;}
				
				editSource(items[0].id, items[0].name);
			});
			$('#btn_source_delete').click(function(){
				var items = tbl.getCheckedRow();
				if(items.length==0){new S.Info({text:'请选择来源',type:'warn'}).show();return;}
				S.confirm('警告','确认删除选中项?',function(){
					var ids = [];
					S.each(items,function(i,item){
						ids.push(item.id);
					});
					S.request({
						url:'${webcontext}/${pathvar.admin}/blog/source/delete',
						data:{ids:ids.join(',')},
						success:function(){
							new S.Info({text:'操作成功',type:'success'}).show();
							tbl.reload();
						}
					});
				},'warn');
			});
			
		});
	</script>
</head>
<body>
	<div class="filled-box">
		<div class="toolbar">
			<span class="btn" id="btn_source_add"><i class="icons plus"></i> 增加</span>
			<span class="btn" id="btn_source_edit"><i class="icons pencil"></i> 修改</span>
			<span class="btn" id="btn_source_delete"><i class="icons cross"></i> 删除</span>
		</div>
		<div class="content">
			<table id="tbl001" height="500" ds="${webcontext }/${pathvar.admin}/blog/source/list">
				<tr>
					<td width="30" seq></td>
					<td width="50" checkall></td>
					<td >名称</td>
				</tr>
				<tr>
					<td>@{seq}</td>
					<td><input type="checkbox" name="id" value="@{id}" /></td>
					<td>@{name}</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>
	